package com.michau.testitas.common.model.testentity;

import com.michau.testitas.common.model.BaseEntity;
import com.michau.testitas.common.model.answer.Answer;
import com.michau.testitas.common.model.definition.Definition;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * User: michau
 * Date: 1/8/13
 * Time: 7:12 PM
 */

@Entity
@Table(name = "testit_testentity")
public class TestEntity extends BaseEntity{

    @Version
    @Column(name = "version", nullable = false)
    private long version;

    @Column(name = "date_created")
    private Date dateCreated;

    // possible problems with removing
    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "answer_id", unique = true)
    private Answer answer;

    @ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.DETACH},
            fetch = FetchType.LAZY)
    @JoinTable(
            name = "testit_testentity_definition",
            joinColumns = {@JoinColumn(name = "testentity_id")},
            inverseJoinColumns = {@JoinColumn(name = "definition_id")}
    )
    private List<Definition> definitions;

    public Answer getAnswer() {
        return answer;
    }

    public void setAnswer(Answer answer) {
        this.answer = answer;
    }

    public List<Definition> getDefinitions() {
        return definitions;
    }

    public void setDefinition(List<Definition> definitions) {
        this.definitions = definitions;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    protected void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public long getVersion() {
        return version;
    }

    protected void setVersion(long version) {
        this.version = version;
    }
}
